#!/bin/bash
#SBATCH -J GROMACS-DCU
#SBATCH -p wzhdnormal
#SBATCH -N 4
##SBATCH -N 1
#SBATCH --ntasks-per-node=4
#SBATCH --cpus-per-task=8
##SBATCH --cpus-per-task=7
#SBATCH --gres=dcu:4
#SBATCH -o log/submit_%j.loop
#SBATCH -e log/submit_%j.loop

source ~/.bashrc
#source /work/home/aixplorerbio_wz/miniconda3/bin/activate amber
#source /work/home/aixplorerbio_wz/software/gromacs-2020.3/bin/GMXRC

module switch compiler/dtk/21.04
module load apps/Gromacs-DCU2/2020.3-dtk21.04/hpcx-gcc-7.3.1

if [ $# != 1 ]; then
    echo "USAGE: $0 $PROJECT_HOME"
    echo " e.g.: $0 ../"
    exit 1
fi

pwd=$(pwd)
PROJECT_HOME=$(cd $1 && pwd)
WORK_PATH=$PROJECT_HOME/work_dir/job

cd $WORK_PATH

srun hostname | sort | uniq | awk '{printf "%s\n",$1}' >hostfile
((num_procs = $SLURM_JOB_NUM_NODES * 4))

# module list
mpirun -hostfile hostfile -np $(ls -d $WORK_PATH/*_md | wc -l) -N 4 --bind-to none $PROJECT_HOME/work_dir/bind.sh
